package org.duanyu.shopping_common.result;

import co.elastic.clients.elasticsearch.xpack.usage.Base;
import lombok.val;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 统一异常处理器
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    //处理业务异常
    @ExceptionHandler(BusException.class)
    public BaseResult defaultExceptionHandler(BusException exception) {
        return new BaseResult(exception.getCode(), exception.getMsg(), null);
    }

    //处理系统异常
    @ExceptionHandler(Exception.class)
    public BaseResult defaultExceptionHandler(Exception exception){
        exception.printStackTrace();
        return new BaseResult(CodeEnum.PARAMETER_ERROR.getCode(), exception.getMessage(), null);
    }

}
